Yacon = {
  
	//浏览器地址判断方法	
    regCheck: function (reg)
    {
        return reg.test(window.uag);
    },
    
    apply:function(obj, org, defaults)
    {
       	if(defaults){
       		Yacon.apply(obj, defaults);
        }  
    	
        if(obj && org && typeof org == 'object'){
            for(var p in org){
            	
                if (Yacon.isObject(obj))
                	obj[p] = org[p];
                else
                	obj.prototype[p] = org[p];
            }
        }
        return obj;
    },
    
	Extend:function(self,par,arg)
	{    	
       	if (!par)
   		  par = Object;    	 
    	  	  
    	  var parObj = new par();
    	  self.prototype = parObj;
    	  self.prototype.constructor = self; 
    	  self.prototype.superclass = parObj;
    	  
		  if(par.constructor == Object.prototype.constructor) 
		  {
			  par.prototype.constructor = par;
		  }
		 
		 if(typeof arg == 'object'){
			 for(var p in arg)
			 {
				 self.prototype[p]=arg[p];
        	 } 
        } 
		
    	return self;
	},
	
    fireUserEvent :function (function_name,param)
    {
    	var result;
        var paramstr="";
        
        if (arguments.length == 2)
    	{
    		for(var i=0; i<param.length; i++)
    		{
    			if (i==0)
    			{	
    				paramstr="param["+i+"]";
                }else
    			{
    				paramstr=paramstr+",param["+i+"]";
    			}
            }
       }
        if (this.isfireuserEvent(function_name)){
         	eval("result="+function_name+"("+paramstr+");");
         }
      
         return result;
    },
   
    isfireuserEvent :function (function_name)
    {	
    	var result = false;
    	
    	if (this.isEmpty(function_name)){
    		return result;
    	}
    	 	
    	eval("result=(typeof("+function_name+")!=\"undefined\");");
    	
    	if(result){
    		Yacon.register(function_name);
    	}
    
        return result;
    },
    
    /* 截取字符串px */
    getPx:function(value){
    	if(this.isDefined(value)){
    		return -1;
    	}
    	return this.getInt(value.substring(0,value.length-2));
    },
    
    getInt:function (value)
    {
    	if (this.isDefined(value))
			return -1;
    	
    	var result = parseInt(value);
    	if (isNaN(result)){ result = -1;}
    	return result;
    },
    
    getFloat:function(value)
    {
    	if (this.isDefined(value))
			return -1;
    	
    	var result = parseFloat(value);
		if (isNaN(result)){ result = -1;}
		return result;
	},
	
	isTrue:function (value)
	{
		if (this.isEmpty(value))
			return false;
		if(this.isBoolean(value))
			return value;
		if (this.isString(value))
		{
			return (value.isEqual("1") ||
				value.toLowerCase().isEqual("true") || value.isEqual("T") ||
				value.toLowerCase().isEqual("yes") || value.toLowerCase().isEqual("on"));
		}
	},
	
    isEmpty : function(obj){
        return obj === null || obj === undefined|| ((Yacon.isString(obj) && !obj.length)) || ((Yacon.isArray(obj) && !obj.length));
    },

    isArray : function(obj){
        return Object.prototype.toString.apply(obj) === '[object Array]';
    },

    isDate : function(obj){
        return Object.prototype.toString.apply(obj) === '[object Date]';
    },

    isObject : function(obj){
    	if (!this.isDefined(obj))
    		return Object.prototype.toString.call(obj) === '[object Object]' ||typeof (obj) == "object";
    	else
    		return false;
    },

    isFunction : function(obj){
        return Object.prototype.toString.apply(obj) === '[object Function]';
    },

    isNumber : function(obj){
        return typeof obj === 'number';
    },    
    isString : function(obj){
        return typeof obj === 'string';
    },

    isBoolean : function(obj){
        return typeof obj === 'boolean';
    },

    isElement : function(obj) {
        return obj ? !!obj.tagName : false;
    },

    isDefined : function(obj){    	
        return typeof obj == 'undefined';
    },
    
    isNull:function(obj){
    	return !obj && typeof obj != "undefined" && obj != 0;
    },
    
    /* 获取页面地址路径 */
    getRootPath:function(){
        //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
        var curWwwPath=window.document.location.href;
        //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
        var pathName=window.document.location.pathname;
        var pos=curWwwPath.indexOf(pathName);
        //获取主机地址，如： http://localhost:8083
        var localhostPaht=curWwwPath.substring(0,pos);
        //获取带"/"的项目名，如：/uimcardprj
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        return(localhostPaht+projectName);
    },
    
    getLocationPath:function(){
    	
    	 var curWwwPath=window.document.location.href;
         //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
         var pathName=window.document.location.pathname;
         var pos=curWwwPath.indexOf(pathName);
         //获取主机地址，如： http://localhost:8083
         var localhostPaht=curWwwPath.substring(0,pos);
         
         return localhostPaht;
         
    },
    
    /* 获取页面相对地址 */
    getRelaPath:function(){
    	var pathName=window.document.location.pathname;
    	return pathName.substr(pathName.substr(1).indexOf('/')+1);
    },

    /* HTTP/HTTPS校验 */
    verifySSL : function(){
    	var rootPath = window.document.location.href;
    	var path = rootPath.indexOf("https://");
    	if(path<0){
    		return false;
    	}else{
    		return true;
    	}
    },
    
    /* 防止普通注入 */   
    stripDefend:function(s){
    	var pattern = new RegExp("[%`~!@#$^&*()=|{}';',\\[\\]<>?~！@#￥……&*（）――|{}【】‘；：”“'。，、？]") ;//格式 RegExp("[在中间定义特殊过滤字符]")
		var rs = "";
		if(s.length > 0){
			for (var i = 0; i < s.length; i++) {
				rs = rs + s.substr(i, 1).replace(pattern, '');
			}
		}
		return rs;
    },
    
    /* 防止SQL注入 */
    stripSQL:function(oField){
    	 var re= /select|update|having|delete|exec|count|’|"|=|;|>|<|%/i;
         if (re.test(oField) ){
            alert("请您不要在参数中输入特殊字符和SQL关键字！");
            return "";
    	 } 
         return oField;
    },
    
    getUrlParam: function(name,url) {
        
        var actUrl = "";
        if(url){
     	   actUrl = url;
        }
        else{
     	   actUrl = location.search;
        }
        
 	   var theRequest = new Object();
 	   if (actUrl.indexOf("?") != -1) {
 	      var str = actUrl.substr(1);
 	      strs = str.split("&");
 	      for(var i = 0; i < strs.length; i ++) {
 	         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
 	      }
 	   }
 	   return theRequest[name];
     },
     
     /* 弹窗 */
     showModal:function(element){
    	 
    	 /* 前置方法 */
    	 Yacon.callBackMethod(element.before);
    	 
    	 /* 存在dataSet */
    	 if(element.dataSet){
    		 
    		 element.dataSet.switchWindow(element);
    		 
    		 var showWindow = new Yacon.widget.TWindow(element);
    		 
    		 showWindow.dataSet = element.dataSet;
    		 
    		 if(!Yacon.isEmpty(element.close)){
    			 showWindow.close = element.close;
    		 }
    		 
    		 showWindow.show();
    		 
    	 }
    	 
    	 /* 不存在dataSet */
    	 else{
    		 
    		 var dataSet;
    		 
    		 if(element.page){
    			 dataSet = new Yacon.data.DataSet(element.page);
    		 }else{
    			 dataSet = new Yacon.data.DataSet(window.page);
    		 }
    		  
    		 Yacon.def.window_idx++;
    		 
    		 dataSet.elementID = "default_window"+Yacon.def.window_idx; 		  
    		 dataSet.switchWindow(element);
    		 
    		 var showWindow = new Yacon.widget.TWindow(element);
    		 showWindow.dataSet = dataSet;
    		 
    		 if(element.page){
    			 showWindow.page = element.page;
    		 }else{
    			 showWindow.page = window.page; 
    		 }
    		 		 
    		 if(!Yacon.isEmpty(element.close)){
    			 showWindow.close = element.close;
    		 }
    		 
    		 /* 页面展示 */
    		 showWindow.show(); 
    		 
    	 }
    	 
    	 /* 后续方法 */
    	 Yacon.callBackMethod(element.after);
    	 
     },
     
/*     easyShowModal:function(element){
    	 
    	  前置方法 
    	 Yacon.callBackMethod(element.before);
    	 
    	  后续方法 
    	 Yacon.callBackMethod(element.after);
    	 
     },*/
     
     addUrlParam: function(paramName,paramValue,url){
    	 
    	 if(url == undefined){
    		 url = window.location.href;
    	 }
    	 
    	 if(paramValue == undefined){
    		 return url;
    	 }
    	 
    	 if(url.indexOf("?")<0){
    		 url += "?"+paramName+"="+paramValue;
 		}else{
 			 url += "&"+paramName+"="+paramValue;
 		}
    	 
    	 return url;
    	 
     },
     
     /* 固定回调 */
     callBackMethod: function(element){
    	 if(!Yacon.isEmpty(element)){
    		 
    		 if(Yacon.isString(element)){
    			 Yacon.callBack(element, []);
    		 }
    		 
    		 else if(Yacon.isObject(element)){
    			 
        		 var method = element.method;
        		 var param = element.param;
        		 
        		 if(Yacon.isEmpty(method)){
        			 return;
        		 }
        		 
        		 if(Yacon.isEmpty(param)){
        			 param = [];
        		 }
        		 
        		 Yacon.callBack(method, param);
        		 
    		 }
    		 
    	 }
    	
     },
     
     /* 自定义回调 */
     callBack: function(methodName, methodParam){
    	 
    	 if(Yacon.isEmpty(methodParam)){
    		 param = [];
    	 }
    	 
    	 if(Yacon.isfireuserEvent(methodName)){    	
    
    		 return Yacon.fireUserEvent(methodName, methodParam); 
    	 }
    	 
     },
     
     /* 右键回调，区域标示与element传入 */
     callBackRight: function(rightDivID,element){
    	 
		if($("#"+rightDivID) == undefined){
			return;
		}
    	 
		$("#"+rightDivID).on("show.bs.context",function () {
			 Yacon.callBack(element.elementID+"_menu_show", [element,element.page]);
		});
		
		$("#"+rightDivID).on("shown.bs.context",function () {
			 Yacon.callBack(element.elementID+"_menu_shown", [element,element.page]);
		});
		
		$("#"+rightDivID).on("hide.bs.context",function () {
			 Yacon.callBack(element.elementID+"_menu_hide", [element,element.page]); 
		});
		
		$("#"+rightDivID).on("hiden.bs.context",function () {
			 Yacon.callBack(element.elementID+"_menu_hiden", [element,element.page]);
		});
    	 
     },
     
     find: function(elementID,fieldName){
    	 
    	 if(Yacon.isEmpty(fieldName)){
    		 var active = $("#"+elementID);    	 
        	 var role = active.attr("lily-player");
        	 
        	 if(role == "tsqlgrid"){    		 
        		 var tsqlgrid = new Yacon.component.TSqlGrid({element:active});   
        		 tsqlgrid.getDataSet();
        		 return tsqlgrid;    		 
        	 }
        	 
        	 else if(role == "twindow"){
        		 return getWindow(elementID);
        	 }
    	 }
    	 
    	 else{
    		 
    		 if(!Yacon.isEmpty(elementID)){
    			 return $("#"+elementID+" .lily-field[field-name='"+fieldName+"']"); 
    		 }else{
    			 return $(".lily-field[field-name='"+fieldName+"']"); 
    		 }
    		    		 
    	 }
    	  
     },
     
	 getWidthNumber: function(widthStr){
		 
		widthStr = widthStr + "";
		
		widthStr = widthStr.trim();
		
		if(widthStr.endWith("px")){
			return parseInt(widthStr.substring(0,widthStr.length-2));
		}
		
		else if(widthStr.endWith("%")){			
			var num = parseInt(widthStr.substring(0,widthStr.length-1)) / 100;		
			return $(window).width() * num;
		}
		
		else{			
			return parseInt(widthStr);		
		}
		
	 },
	 
	 getHeightNumber: function(heightStr){
		 
			heightStr = heightStr + "";
			
			heightStr = heightStr.trim();
			
			if(heightStr.endWith("px")){
				return parseInt(heightStr.substring(0,heightStr.length-2));
			}
			
			else if(heightStr.endWith("%")){			
				var num = parseInt(heightStr.substring(0,heightStr.length-1)) / 100;		
				return $(window).height() * num;
			}
			
			else{			
				return parseInt(heightStr);		
			}
			
		 },
     
     /* 获取地址参数信息 */
     findParam: function(paramName,url){
    	 return Yacon.getUrlParam(paramName, url);
     },
     
     upload: function(fileID,callBack,isPortal){
    	 
    	 if(isPortal == undefined){
    		 isPortal = false;
    	 }
    	 
    	 var url = "/UI/portalbs/tools/file/fileUpload.jsp";
    	 var adapterUrl = getAbsolutePath(url);
    	 
    	 if(Yacon.isTrue(isPortal)){
    		 adapterUrl = Yacon.getRootPath()+url;
    	 }
    	 
    	 var setting = {
    		 url: adapterUrl+"?fileID="+fileID,
    		 width: "630px",
    		 heigth: "100px"
    	 }
    	 
    	 if(!Yacon.isEmpty(callBack)){
    		 setting.close = callBack;
    	 }
    	 
    	 Yacon.showModal(setting);
     },
     
     download: function(filePath){
		 var test=window.open(filePath); 
		 test.document.execCommand("SaveAs");   
		 window.close(); 
		 test.close();    	 
     },
     
     easyDownload:function(element){
    	 
    	var filePath = "";
     	var fileCharset = "";
     	var fileLocation = "";
     	
     	var appCode = "";
    	
    	if(Yacon.isString(element)){
    		filePath = element;
         	fileCharset = "UTF-8";
         	fileLocation = "webroot";
    	}else {
    		filePath = element.filePath;
    		
         	fileCharset = element.fileCharset;
         	if(Yacon.isEmpty(fileCharset)){
         		fileCharset = "UTF-8";
         	}
         	
         	fileLocation = element.fileLocation;
         	if(Yacon.isEmpty(fileCharset)){
         		fileLocation = "webroot";
         	}
    	}
    	
    	var url = "/easyDown";	
    	
    	var adapterUrl = getAbsolutePath(url);
    	
    	adapterUrl += "?filePath="+filePath.encode()+"&fileCharset="+fileCharset+"&fileLocation="+fileLocation;
    	
    	window.open(adapterUrl);
    	 
     },
     
     sleep: function (numberMillis) {
	    var now = new Date();
	    var exitTime = now.getTime() + numberMillis;
	    while (true) {
	        now = new Date();
	        if (now.getTime() > exitTime)
	            return;
	    }
	 },
	 
	 getImageInfo: function(url){
		
		var start_time = new Date().getTime();
		  
		// 图片地址
		var img_url = url+"?"+start_time;
		  
		// 创建对象
		var img = new Image();
		  
		// 改变图片的src
		img.src = img_url;
		
		var imgHeight = "";
		var imgWidth = "";
		  
		// 定时执行获取宽高
		var check = function(){

			 if(img.width>0 || img.height>0){
			
				 imgHeight += img.height;
				 imgWidth += img.height;
				 clearInterval(set);
				 
			 }
		};
		  
		var set = setInterval(check,40);
		
		alert(imgHeight);
		alert(imgWidth);
	 },
	 
	 getNowFormatDateTime : function() {

		    var date = new Date();

		    var seperator1 = "-";

		    var seperator2 = ":";

		    var month = date.getMonth() + 1;

		    var strDate = date.getDate();

		    if (month >= 1 && month <= 9) {

		        month = "0" + month;

		    }

		    if (strDate >= 0 && strDate <= 9) {

		        strDate = "0" + strDate;

		    }

		    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate

		            + " " + date.getHours() + seperator2 + date.getMinutes()

		            + seperator2 + date.getSeconds();

		    return currentdate;

	},
	
	getNowFormatDate: function(){
		
	    var date = new Date();

	    var seperator1 = "-";

	    var seperator2 = ":";

	    var month = date.getMonth() + 1;

	    var strDate = date.getDate();

	    if (month >= 1 && month <= 9) {

	        month = "0" + month;

	    }

	    if (strDate >= 0 && strDate <= 9) {

	        strDate = "0" + strDate;

	    }

	    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;

	    return currentdate;
	},
	
    getNowFormatTime: function(){
		
	    var date = new Date();

	    var seperator1 = "-";

	    var seperator2 = ":";

	    var month = date.getMonth() + 1;

	    var strDate = date.getDate();

	    if (month >= 1 && month <= 9) {

	        month = "0" + month;

	    }

	    if (strDate >= 0 && strDate <= 9) {

	        strDate = "0" + strDate;

	    }

	    var currentdate = date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();;

	    return currentdate;
	},
	
	/* 注册对象  */
	register:function(element){
		Yacon.env.add(element);
	},
	
	/* 取消注册过的对象 */
	unload:function(){
		var size = Yacon.env.length;
		
		if(size<=0){
			return;
		}else{
			
			for(var i=0;i<size;i++){
				eval("delete window."+Yacon.env[i]+";")
			}
			
			Yacon.env.clear();
			Yacon.env = [];
			
		}
	},
	
	/* 添加Token */
	addToken: function(url){
		
		url = Yacon.addUrlParam("tokenID", lilyEns().encode(), url);
		
		return url;
		
	},
	
	updateToken: function(){
		
		$.ajax({    			
			type: "POST",
		    url: Yacon.getRootPath()+"/portalService?commID=tks&&tokenID="+lilyEns().encode(),
		    processData: false,
		    async: false,
		    dataType: 'text', 
		    success: function(data){
		    	
		    	var rsp = JSON.parse(data);
		     	 
		     	window.ske = rsp.ske.decode();
		    	
		    }
		});
		
	},
	
	ens: function(msg){
		return Yacon.security.eds(msg);
	},
	
	throwException: function(msg){
		if(msg){
			var exception = new CommonException(msg, 1);  				  
	        throw exception; 
		}else{
			var exception = new CommonException('您的代码出错了！', 1);  				  
	        throw exception; 
		}
		
	}
};

Yacon.util = {};
Yacon.data = {};
Yacon.view = {};
Yacon.container = {};
Yacon.widget = {};
Yacon.component = {};
Yacon.dispatch = {};
Yacon.dispatch.msg = {};
Yacon.env = [];

/**
 * 初始构造函数
 */
(function(){  
	      
	window.uag = navigator.userAgent.toLowerCase();
    window.docMode = document.documentMode;
    window.isStrict = document.compatMode == "CSS1Compat";
    window.isfirefox = Yacon.regCheck(/firefox/);
    window.isOpera = Yacon.regCheck(/opera/);
    window.isChrome = Yacon.regCheck(/\bchrome\b/);
    window.isWebKit = Yacon.regCheck(/webkit/);
    window.isSafari = !isChrome && Yacon.regCheck(/safari/);
    window.isSafari2 = isSafari && Yacon.regCheck(/applewebkit\/4/);
    window.isSafari3 = isSafari && Yacon.regCheck(/version\/3/);
    window.isSafari4 = isSafari && Yacon.regCheck(/version\/4/);
    window.isIE11 = uag.indexOf("trident") > -1 && uag.indexOf("rv") > -1;
    window.isIE = Yacon.regCheck(/msie/);    
    window.isIE10 = isIE && (Yacon.regCheck(/msie 10/));
    window.isIE9 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/9./i)=="9.");
    window.isIE7 = isIE && (Yacon.regCheck(/msie 7/) || docMode == 7);
    window.isIE8 = isIE && (Yacon.regCheck(/msie 8/) && docMode != 7);
    window.isIE6 = isIE && (Yacon.regCheck(/msie 6/) && docMode != 7);
    window.isGecko = !isWebKit && Yacon.regCheck(/gecko/);
    window.isGecko2 = isGecko && Yacon.regCheck(/rv:1\.8/);
    window.isGecko3 = isGecko && Yacon.regCheck(/rv:1\.9/);
    window.isBorderBox = isIE && !isStrict;
    window.isWindows = Yacon.regCheck(/windows|win32/);
    window.isMac = Yacon.regCheck(/macintosh|mac os x/);
    window.isAir = Yacon.regCheck(/adobeair/);
    window.isLinux = Yacon.regCheck(/linux/);
    window.isSecure = /^https/i.test(window.location.protocol);
  
    if(window.isIE6){
        try{
        	document.execCommand("BackgroundImageCache", false, true);
        }catch(e){}
    }
    window.constErrUnknown = "程序引起未知错误！";
        
})();

Yacon.def =
{
	window_ico : "glyphicon glyphicon-user",	
	window_idx : 1,
    modulus : "008e009062d23d9959d631fdb8b84c88c0ac3c68425946ecacbbb74b9f05d27131e6be5cd1cf9daaadbb4109733c61e772e2fefabe07a87bd9fc00ac0d83ea29de7ac9e6463f455f5e63dc18601c0111e5f94b5d020196be30e117c7bccc9311c93c1b9d29d85e9430fc08981f7f525ee6721357091f95217831c4a947c3fc85dd",
    exponent : "010001"
};

/* 文件上传 */
function upLoadFile(fileID)
{
	var dialogArg = "dialogwidth:600px; Dialogheight:100px;center:yes;help:no;resizable:no;scroll:no;status:no";
	var arg = new Object();			
	var dd  = window.showModalDialog(page.element.contextPath+"/UI/portal/fileupload/fileupload.jsp?fileID="+fileID,arg, dialogArg);
}

function lilyEns(){	
	return Yacon.security.eds(window.ske);
}
